
import {colorList} from "../bgColorControl";
import AudioManage, {soundList} from "../../framework/AudioManage";
import mainManage from "../../framework/mainManage";
import settingMediator from "../../framework/settingMediator";
import sceneMediator from "../../framework/sceneMediator";
import {actionType} from "../portalMediator";
import {toolList} from "../handControl";
import Tool from "../../framework/Tool";
import gameData from "../gameData";

const {ccclass, property} = cc._decorator;

let tipList = [
    ["你…你是BUG君!","可恶!他们居然把你封印在这种绝境里!"],
    ["我是BUG的制造者,这是我应得的惩罚!","勇者大人,你离开吧,让我自生自灭…"],
    ["不!你应该站出来,去修复勇者世界的错误!","我们要一起打败大魔王!救出宠物们!"],
    ["你说的对,我不应该逃避","可是熄灭火焰的唯一方法,只有…"],
    ["火焰禁制打开了!","可是BUG君,我们离得太远了…"],
    ["还差最后一步","你要激活石阶","才能到我这里来"]
];

export enum actionList {
    action1 = 0,
    action2 = 1,
    action3 = 2,
    action4 = 3,
    action5 = 4,
    action6 = 5,
    action7 = 6,
    action8 = 7,
    action9 = 8,
    action10 = 9,
    action11 = 10,
    action12 = 11,
    action13 = 12,
    action14 = 13,
    action15 = 14,
    action16 = 15
}

@ccclass
export default class actionMediator extends cc.Component {

    @property({type : cc.Enum(actionList),displayName : "动作列表"})
    curAction : actionList = actionList.action1;

    //第八关判断失败的逻辑
    isTouchTrigger : boolean = false;

    isGameOver : boolean = false;

    //game11开关触发顺序列表
    openList = [0,2,4,1,3,5];

    //game11连续点击开关触发
    continuousOpenSwitch = 0;

    //game11打开开关的顺序
    openOrder  = 0;

    //game11打开开关次数
    continuousOpenTimes  = 0;

    //game12板子初始位置
    initPos = null;

    //game12板子触摸移动的位置
    movePos = null;

    @property(cc.Node)
    nodeList : cc.Node[] = [];

    @property(cc.SpriteFrame)
    skinList : cc.SpriteFrame[] = [];

    @property({type : cc.Component.EventHandler,displayName : "触发事件"})
    toolEvent : cc.Component.EventHandler[] = [];

    onLoad(){
        switch (this.curAction) {
            case actionList.action1 :
                if(sceneMediator.curEnterLevel == 1 && sceneMediator.princeShowLevel == 8){
                    cc.game.on("showActionPrince8",(res)=>{
                        if(res == 1){
                            this.MaraLevel86(); //问题
                        }else if(res == 2){
                            this.MaraLevel810(); //皮肤
                        }else if(res == 3){
                            this.MaraLevel89();  //宠物
                        }else if(res == 4){
                            // this.MaraLevel811();  //线索
                        }
                    });
                }

                if(sceneMediator.curEnterLevel == 1 && sceneMediator.princeShowLevel == 7){
                    cc.game.on("showThreadPrince",()=>{
                        this.MaraLevel811();
                    });
                }
                break;
            case actionList.action2 :
                this.gameAction2();
                break;
            case actionList.action3 :
                this.gameAction3();
                break;
            case actionList.action5 :
                break;
            case actionList.action7 :
                if(sceneMediator.getShowScene() == 14){
                    this.node.on("touchstart",this.TouchStart14,this);
                    this.node.on("touchend",this.TouchEnd14,this);
                }
                break;
            case actionList.action6 :
                this.initPos = this.node.position;
                this.node.on("touchstart",this.initTablePos,this);
                this.node.on("touchmove",this.tableMove,this);

                if(sceneMediator.curEnterLevel == 0 && sceneMediator.getShowScene() == 8){
                    this.gameGuideAction8();
                }

                break;
            case actionList.action8 :
                this.nodeList[6].on("touchstart",this.hideEyes,this);
                this.nodeList[6].on("touchend",this.showEyes,this);
                this.nodeList[6].on("touchcancel",this.showEyes,this);
                break;
            case actionList.action9 :
                this.node.on("touchstart",this.initTablePos,this);
                this.node.on("touchmove",this.tableMoveX,this);
                this.nodeList[0].on("touchcancel",this.tableCancelX,this);
                break;
            case actionList.action10 :
                this.stabMoveAction50();
                break;
            case actionList.action11:
                this.nodeList[1].x = -cc.view.getVisibleSize().width / 2  - this.nodeList[1].width  / 2;
                this.nodeList[2].x = -cc.view.getVisibleSize().width / 2 - 50;
                break;
            case actionList.action12:
                break;
            case actionList.action13:
                this.nodeList[0].getComponent("conversationWindow").setCallBack(1,()=>{
                    this.nodeList[2].active = true;
                });
                this.nodeList[0].active = true;
                break;
            case actionList.action14:
                cc.game.on("showEggView",(res)=>{
                    if(res == 1){
                        this.MaraLevel51();
                    }else if(res == 2){
                        this.MaraLevel52();
                    }else if(res == 3){
                        this.MaraLevel56();
                    }else if(res == 4){
                        this.MaraLevel57();
                    }
                });
                break;
            case actionList.action15:
                this.nodeList[0].on("touchend",this.MaraLevel62,this);
                if(sceneMediator.curEnterLevel == 1 && sceneMediator.princeShowLevel == 6){

                    this.nodeList[3].active = false;
                    Tool.loadPrefab("prefabs/letter",(res)=>{
                        let view = cc.instantiate(res);
                        view.getComponent("letterMediator").setCallBack(()=>{
                            this.nodeList[2].getComponent("conversationWindow").setCallBack(3,()=>{
                                this.nodeList[3].active = true;
                            });
                            this.nodeList[2].active = true;
                        });
                        view.zIndex = 500;
                        view.parent = cc.find("Canvas");
                    })
                }
                break;
            case actionList.action16:
                break;
        }

        if(gameData.colorfulPiece[1][0] == 0 && sceneMediator.getShowScene() == 24){
            let spk = this.nodeList[13].getComponent(sp.Skeleton);
            spk.setAnimation(0,"archenemy2",true);
        }
    }

    protected onDestroy(): void {
        cc.game.off("showEggView");
        if(sceneMediator.curEnterLevel == 1 && sceneMediator.princeShowLevel == 8){
            cc.game.off("showActionPrince8");
        }

        if(sceneMediator.curEnterLevel == 1 && sceneMediator.princeShowLevel == 7){
            cc.game.off("showThreadPrince");
            cc.game.off("showEnter");
        }

    }

    tableMove(event){
        if(this.node.y <= this.initPos.y - 200) return;
        let worldPoint = event.getLocation();
        let pos = this.node.convertToNodeSpaceAR(worldPoint);
        if(this.node.y + (pos.y - this.movePos.y) >= cc.winSize.height / 2 - this.node.height /2){
            this.node.y = cc.winSize.height / 2 - this.node.height /2;
        }else{
            this.node.y += (pos.y - this.movePos.y);
        }
        this.movePos = pos;
    }

    tableMoveX(event){
        let worldPoint = event.getLocation();
        let pos = this.node.convertToNodeSpaceAR(worldPoint);
        if(this.nodeList[0].x + (pos.x - this.movePos.x) >= 300){
            this.nodeList[0].x = 300;
        }else if(this.nodeList[0].x + (pos.x - this.movePos.x) <= -200){
            this.nodeList[0].x = -200;
        }else{
            this.nodeList[0].x += (pos.x - this.movePos.x);
        }
        this.movePos = pos;
    }

    tableCancelX(event){

    }

    initTablePos(event){
        let worldPoint = event.getLocation();
        let pos = this.node.convertToNodeSpaceAR(worldPoint);
        this.movePos = pos;

        if(sceneMediator.curEnterLevel == 0 && sceneMediator.getShowScene() == 8){
            this.nodeList[0].active = false;
        }

    }

    titleAction11(){
        cc.tween(this.nodeList[0]).by(0.3,{
            position : cc.v2(-200,0)
        })
    }

    gameAction1(){
        cc.tween(this.node.getChildByName("stab1")).by(0.3,{
            position : cc.v2(0,150)
        }).start();

        cc.tween(this.node.getChildByName("stab2")).by(0.3,{
            position : cc.v2(0,-150)
        }).start();

        cc.tween(this.node.getChildByName("stab3")).by(0.3,{
            position : cc.v2(0,35)
        }).start();

        cc.tween(this.node.getChildByName("stab4")).by(0.3,{
            position : cc.v2(0,40)
        }).start();

        cc.tween(this.node.getChildByName("stab5")).by(0.3,{
            position : cc.v2(0,-45)
        }).call(()=>{
            cc.game.emit("setColor",colorList.red);
            AudioManage.playSFX(soundList.meetEvil,false,false,1);
        }).start();
    }

    gameAction11(){
        cc.tween(this.node.getChildByName("door1")).by(0.8,{
            position : cc.v2(-150,0)
        }).call(()=>{
            cc.tween(this.node.getChildByName("door2")).by(0.8,{
                position : cc.v2(150,0)
            }).call(()=>{
                AudioManage.playSFX(soundList.meetEvil,false,true,1);
            }).start();
        }).start();
    }

    gameAction2(){
        this.scheduleOnce(()=>{
            if(this.isGameOver) return;
            this.node.getChildByName("key1").active = true;
            this.scheduleOnce(()=>{
                if(this.isGameOver) return;
                this.node.getChildByName("key2").active = true;
            },1);
            this.scheduleOnce(()=>{
                if(this.isGameOver) return;
                this.node.getChildByName("key3").active = true;
            },1.2);
            this.scheduleOnce(()=>{
                if(this.isGameOver) return;
                this.node.getChildByName("key4").active = true;
            },1.4);
            this.scheduleOnce(()=>{
                if(this.isGameOver) return;
                this.node.getChildByName("key5").active = true;
            },1.6);
            this.scheduleOnce(()=>{
                if(this.isGameOver) return;
                this.gameAction21();
            },2);
        },4);

    }

    gameAction21(){
        this.node.getChildByName("effect").active = true;
        this.scheduleOnce(()=>{
            if(this.isGameOver) return;
            this.node.getChildByName("stone").active = true;
            this.scheduleOnce(()=>{
                this.node.getChildByName("wall").active = true;
            },0.5);
            this.scheduleOnce(()=>{
                if(this.isGameOver) return;
                this.isTouchTrigger = true;
                cc.game.emit("closeClickListen");
                cc.game.emit("setTitle");
                this.node.getChildByName("lightGroup").active = true;
                this.node.getChildByName("key1").active = false;
                this.node.getChildByName("key2").active = false;
                this.node.getChildByName("key3").active = false;
                this.node.getChildByName("key4").active = false;
                this.node.getChildByName("key5").active = false;
                this.node.getChildByName("stone").active = false;
                this.node.getChildByName("wall").active = false;
                cc.Component.EventHandler.emitEvents(this.toolEvent,[]);
            },2)
        },1);
    }

    //第八关游戏结束
    gameOverAction22(){
        console.log(this.isTouchTrigger,"this.isTouchTrigger============>")
        if(!this.isTouchTrigger){
            this.isGameOver = true;
            AudioManage.playSFX(soundList.arrowMove,false);
            let children1 = this.node.getChildByName("leftStab").children;
            let children2 = this.node.getChildByName("rightStab").children;
            for(let i in children1){
                cc.tween(children1[i]).by(3,{
                    position : cc.v2(cc.winSize.width * 2 ,0)
                }).start();
                cc.tween(children2[i]).by(3,{
                    position : cc.v2(-cc.winSize.width * 2,0)
                }).start();
            }
        }else{
            cc.game.emit("setTitle");
            let children = this.node.getChildByName("upDownStab").children;
            for(let i in children){
                let target = children[i];
                let index = parseInt(i);
                if(parseInt(i) % 2 == 1){
                    cc.tween(children[i]).by(1,{
                        position : cc.v2(0,-350)
                    }).call(()=>{
                        this.scheduleOnce(()=>{
                            cc.tween(target).by(2,{
                                position : cc.v2(0,350)
                            }).start();
                        },3);
                    }).start();
                }else{
                    cc.tween(children[i]).by(1,{
                        position : cc.v2(0,350)
                    }).call(()=>{
                        this.scheduleOnce(()=>{
                            cc.tween(target).by(2,{
                                position : cc.v2(0,-350)
                            }).call(()=>{
                              if(index == children.length - 1 ){
                                  cc.game.emit("setTitle");
                              }
                            }).start();
                        },3);
                    }).start();
                }
            }
        }
    }

    gameAction3(){
        cc.tween(this.node).repeatForever(
            cc.tween(this.node)
                .by(2,{position : cc.v2(0,150)})
                .by(2,{position : cc.v2(0,-150)})
        ).start();
    }

    showGuide3(){
        this.nodeList[0].active = true;
    }

    gameAction4(){
        this.node.getChildByName("key").active = true;
        cc.game.emit("setTitle");
    }

    //第八关引导
    gameGuideAction8(){
        let arrow = this.nodeList[0].getChildByName("arrow");
        let hand = this.nodeList[0].getChildByName("hand");
        cc.tween(hand)
            .to(0.4,{scale : 0.8})
            .by(0.5,{y : -100})
            .delay(0.5)
            .call(()=>{
                hand.y += 100;
                hand.scale = 1;
                this.gameGuideAction8();
            })
            .start();
        cc.tween(arrow)
            .delay(0.5)
            .to(0.4,{scale : 1})
            .call(()=>{
                arrow.scaleX = 0;
            })
            .start();
    }

    //第九关设置地板的皮肤
    setTableSkin(open){
        if(open){
            this.node.getComponent(cc.Sprite).spriteFrame = this.skinList[0];
        }else{
            this.node.getComponent(cc.Sprite).spriteFrame = this.skinList[1];
        }
    }


    //game11按钮的逻辑判断
    gameAction5(event){
        let data = event[0];
        if(this.openOrder == -1){
            if(this.continuousOpenSwitch == parseInt(data)){
                this.continuousOpenTimes++;
                if(this.continuousOpenTimes >= 10){
                    this.continuousOpenTimes = -1000;
                    this.nodeList[0].group = "default";
                    this.nodeList[0].getComponent("toolTypeList").toolType = toolList.openSwitch;
                    this.nodeList[1].getComponent("handControl"). disappear = true;
                }
            }
        }else{
            if(this.openList[this.openOrder] == parseInt(data)){
                this.openOrder++;
            }else{
                console.log("游戏结束");
                cc.game.emit("GameOver");
                settingMediator.doVibration(2);
                let spk = cc.find("Canvas/role").getChildByName("spine").getComponent(sp.Skeleton);
                spk.setAnimation(0,"die",false);
                this.scheduleOnce(()=>{
                    cc.game.emit("gameLose");
                },2);
                cc.Component.EventHandler.emitEvents(this.toolEvent, []);
            }
            if(this.openOrder >= this.openList.length){
                this.openOrder = -1;
                this.node.getChildByName("key").active = true;
            }
        }
    }

    showUnlockSkin(event){
        if(event[0] == 2){
            Tool.loadPrefab("prefabs/eggSkin",(res)=>{
                let view = cc.instantiate(res);
                view.getComponent("eggSkin").setCallBack(9,1,()=>{

                });
                view.parent = cc.find("Canvas");
            })
        }
    }

    //game14背景的触摸事件
    pos1 = 0;
    TouchStart14(event){
        let worldPoint = event.getLocation();
        let pos = this.node.convertToNodeSpaceAR(worldPoint);
        this.pos1 = pos.x;
    }

    // TouchMove14(event){
    //     let worldPoint = event.getLocation();
    //     let pos = this.node.convertToNodeSpaceAR(worldPoint);
    //     this.pos1 = pos.x;
    // }
    changeBGTimes = 0;
    TouchEnd14(event){
        let worldPoint = event.getLocation();
        let pos = this.node.convertToNodeSpaceAR(worldPoint);
        if(pos.x - this.pos1 < -30){
            this.changeBGTimes++;
            if(this.changeBGTimes > 2) return;
            if(this.changeBGTimes == 2){
                this.nodeList[0].active = false;
            }
            let children = this.node.getChildByName("view").getChildByName("content").children;
            for(let i in children){
                children[i].x -= children[i].width;
            }
        }

        this.pos1 = 0;
    }
    gameAction7(){
        // let target = this.node.getComponent(cc.PageView);
        // if(target.getCurrentPageIndex() == 2){
        //     this.nodeList[0].active = false;
        // }else{
        //     this.nodeList[0].active = true;
        // }
        // let children = this.node.getChildByName("view").getChildByName("content").children[0];
        // children.active = false;
        // this.node.getChildByName("view").getChildByName("content").width -= children.width;
        // this.node.getChildByName("view").getChildByName("content").x += children.width;
    }

    //game15边刺的显示
    gameAction8(){
        this.nodeList[0].active = true;
        this.nodeList[1].active = true;
    }

    clickTimes = 0;
    //game17显示传送门
    gameAction17(){
        this.clickTimes++;
        this.nodeList[1].getComponent(cc.Sprite).spriteFrame = this.skinList[this.clickTimes - 1];
        if(this.clickTimes > 3){
            this.nodeList[0].active = true;
            this.node.active = false;
            this.nodeList[1].active = false;
        }
    }

    isShow = true;
    //game19显示假的地刺
    gameAction18(event){
        if(this.isShow){
            for(let i in this.node.children){
                this.node.children[i].opacity = 100;
            }
        }else{
            for(let i in this.node.children){
                this.node.children[i].opacity = 255;
            }
        }

        this.isShow = !this.isShow;
    }

    //game20显示挡板
    gameAction20(){
        this.nodeList[0].active = !this.isShow;
        this.isShow = !this.isShow;
    }

    showPart = 0;
    //game18楼梯下沉
    gameAction19(){
        if(this.showPart == 0){
            this.tableFallDown(-110);
            this.nodeList[0].getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic;
            this.nodeList[1].getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic;
            this.showPart++;
        }else if(this.showPart == 1){
            this.tableFallDown(-120);
            this.nodeList[2].getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic;
            this.nodeList[3].getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic;
            this.showPart++;
        }else if(this.showPart == 2){
            this.tableFallDown(-150);
            this.nodeList[4].getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic;
            this.nodeList[5].getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic;
            this.showPart++;
        }
    }

    tableFallDown(height){
        cc.tween(this.nodeList[6]).by(0.3,{
            position : cc.v2(0,height)
        }).start();
        cc.tween(this.nodeList[7]).by(0.3,{
            position : cc.v2(0,height)
        }).start();
        cc.tween(this.nodeList[8]).by(0.3,{
            position : cc.v2(0,height)
        }).start();
    }


    tableMoveUp(){
        cc.tween(this.nodeList[6]).by(0.4,{
            position : cc.v2(0,80)
        }).start();
        cc.tween(this.nodeList[7]).by(0.4,{
            position : cc.v2(0,80)
        }).start();
        cc.tween(this.nodeList[8]).by(0.4,{
            position : cc.v2(0,80)
        }).start();
    }

    //game21地刺消失
    stabDisappear(){
        this.nodeList[0].active = false;
    }

    tableMove21(){
        cc.tween(this.nodeList[1]).by(0.3,{
            position : cc.v2(this.nodeList[1].width,0)
        }).start();
    }

    lableShow21(){
        this.nodeList[2].active = true;
    }

    arrowGroupMove(){
        // let pos = cc.find("Canvas/role").convertToWorldSpaceAR(cc.v2(0,0));
        // let pos2 = cc.find("Canvas").convertToNodeSpaceAR(pos);
        let pos = cc.find("Canvas/role").x;

        console.log("position", cc.find("Canvas/role").x);
        cc.tween(this.nodeList[3])
            .to(0.01,{x : pos})
            // .delay(1)
            .by(1,{
                position : cc.v2(0,-cc.winSize.height)
            })
            .start();
    }

    //关卡22多次按按钮
    pressBtnTimes = [false,false];
    isOpen = false;
    pressBtnMore221(event,data){
        if(this.isOpen) return;
        this.pressBtnTimes[parseInt(data) - 1] = !this.pressBtnTimes[parseInt(data) - 1];
        let index = true;
        for(let i in this.pressBtnTimes){
            if(this.pressBtnTimes[i] == false){
                index = false;
            }
        }
        if(index){
            this.isOpen = true;
            this.nodeList[0].active = false;
            cc.Component.EventHandler.emitEvents(this.toolEvent, []);
        }
    }

    pressBtnTimes2 = [false,false,false,false];
    pressBtnMore222(event,data){
        if(this.isOpen) return;
        this.pressBtnTimes2[parseInt(data) - 1] = !this.pressBtnTimes2[parseInt(data) - 1];
        let index = true;
        for(let i in this.pressBtnTimes2){
            if(this.pressBtnTimes2[i] == false){
                index = false;
            }
        }
        if(index){
            this.isOpen = true;
            this.nodeList[0].active = false;
            cc.Component.EventHandler.emitEvents(this.toolEvent, []);
        }
    }

    //game23相机移动
    cameraMovingAction1(){
        cc.Camera.main.node.y += cc.winSize.height;
    }
    cameraMovingAction2(){
        cc.Camera.main.node.y -= cc.winSize.height;
    }

    showMaskNode23 = true;
    showMask23(){
        if(!this.showMaskNode23){
            this.nodeList[2].active = true;
            this.showMaskNode23 = true;
        }else{
            this.nodeList[2].active = false;
            this.showMaskNode23 = false;
        }
    }

    tableDisappear23(){
        this.nodeList[0].destroy();
        this.nodeList[1].destroy();
    }

    //game25地刺和背景逻辑
    showBackGround = false;
    stabBackGroundActionShow(){
        this.showBackGround = !this.showBackGround;
        if(this.showBackGround){
            this.nodeList[0].opacity = 255;
            this.nodeList[1].active = false;
            let children = this.nodeList[0].children;
            for(let i in children){
                children[i].group = "role";
                children[i].getComponent(cc.PhysicsPolygonCollider).enabled = false;
            }
        }else{
            this.nodeList[0].opacity = 0;
            this.nodeList[1].active = true;
            let children = this.nodeList[0].children;
            for(let i in children){
                children[i].group = "stab";
                children[i].getComponent(cc.PhysicsPolygonCollider).enabled = true;
            }
        }
    }

    //game27旋转地刺的逻辑
    stabRotation = true;
    rotationStab(){
        if(this.stabRotation){
            for(let i in this.nodeList){
                this.nodeList[i].getComponent(cc.RigidBody).type = cc.RigidBodyType.Static;
            }
        }else{
            for(let i in this.nodeList){
                this.nodeList[i].getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic;
            }
        }
        this.stabRotation = !this.stabRotation;
    }


    //game28所有逻辑
    showMonster(){
        this.scheduleOnce(()=>{
            this.node.children[0].active = true;
            this.scheduleOnce(()=>{
                this.node.children[1].active = true;
                this.scheduleOnce(()=>{
                    this.node.children[2].active = true;
                    this.scheduleOnce(()=>{
                        this.node.children[3].active = true;
                    },0.1)
                },0.1)
            },0.1)
        },0.1)
    }

    showMonster4(){
        this.node.children[4].active = true;
    }

    showMonster5(){
        this.node.children[5].active = true;
    }

    showMonster6(){
        this.node.children[6].active = true;
    }

    showTriggerNode(){
        for(let i in this.nodeList[1].children){
            this.nodeList[1].children[i].active = true;
        }
    }

    //game28钻石幽灵的逻辑
    diamondTree(){
        this.nodeList[0].active = true;
        this.nodeList[2].active = true;
        if(gameData.colorfulPiece[1][2] == 0){
            this.nodeList[3].active = true;
        }
        cc.find("Canvas/role").getComponent("roleMediator").setRoleProcessKey(null);
        cc.game.emit("openFollow",this.nodeList[0],3.5);
    }


    //game28传送门相机移动
    lastCameraPosition = null;
    movePositionIndex = 1;
    cameraMoveAction28(){
        if(this.movePositionIndex == 1){
            this.lastCameraPosition = cc.Camera.main.node.position;
            cc.Camera.main.node.x = 0;
            cc.Camera.main.node.y = 750;
            this.movePositionIndex = 2
        }else {
            cc.Camera.main.node.x = this.lastCameraPosition.x;
            cc.Camera.main.node.y = this.lastCameraPosition.y;
            this.movePositionIndex = 1;
        }
    }

    //game24苹果监听事件
    pumpkinNumber = 0;
    pumpkinListenEvent(){
        this.pumpkinNumber++;
        this.nodeList[3 + this.pumpkinNumber].active = true;
        // console.log(gameData.getLevelPumpkin()[sceneMediator.getShowScene() - 1]);
        if(this.pumpkinNumber >= gameData.getLevelPumpkin()[sceneMediator.getShowScene() - 1]){
            cc.game.emit("shieldPressKey",true);

            //狗头皮肤提示
            // if(gameData.colorfulPiece[1][0] == 0){
            //     cc.tween(this.nodeList[0]).by(1,{
            //         position : cc.v2(0,200)
            //     }).call(()=>{
            //         this.nodeList[9].active = true;
            //         this.scheduleOnce(()=>{
            //             this.nodeList[9].active = false;
            //             this.nodeList[10].active = true;
            //             this.scheduleOnce(()=>{
            //                 this.nodeList[10].active = false;
            //                 this.nodeList[11].active = true;
            //                 this.scheduleOnce(()=>{
            //                     this.nodeList[11].active = false;
            //                     this.nodeList[12].active = true;
            //
            //                     let spk = this.nodeList[13].getComponent(sp.Skeleton);
            //                     spk.setAnimation(0,"archenemy",true);
            //                     this.nodeList[14].active = true;
            //                     cc.tween(this.nodeList[14]).to(0.5,{
            //                         position : cc.v2(0,0)
            //                     }).call(()=>{
            //                         this.nodeList[14].active = false;
            //                         gameData.colorfulPiece[1][0] = 1;
            //                         gameData.saveColorfulPiece();
            //                         // Tool.loadPrefab("prefabs/getPiece",(res)=>{
            //                         //     let view = cc.instantiate(res);
            //                         //     view.getComponent("getMaPiece").setCallBack(1);
            //                         //     view.parent = cc.find("Canvas");
            //                         // });
            //                         cc.game.emit("shieldPressKey",false);
            //                         cc.Component.EventHandler.emitEvents(this.toolEvent, []);
            //                     }).start();
            //                 },4)
            //             },4)
            //         },4)
            //     }).start();
            // }else{
            //     cc.tween(this.nodeList[0]).by(1,{
            //         position : cc.v2(0,300)
            //     }).call(()=>{
            //         this.nodeList[1].active = true;
            //         this.scheduleOnce(()=>{
            //             this.nodeList[1].active = false;
            //             this.nodeList[2].active = true;
            //             this.scheduleOnce(()=>{
            //                 this.nodeList[2].active = false;
            //                 this.nodeList[3].active = true;
            //                 cc.game.emit("shieldPressKey",false);
            //                 cc.Component.EventHandler.emitEvents(this.toolEvent, []);
            //             },2)
            //         },2)
            //     }).start();
            // }

            cc.tween(this.nodeList[0]).by(1,{
                position : cc.v2(0,300)
            }).call(()=>{
                this.nodeList[1].active = true;
                this.scheduleOnce(()=>{
                    this.nodeList[1].active = false;
                    this.nodeList[2].active = true;
                    this.scheduleOnce(()=>{
                        this.nodeList[2].active = false;
                        this.nodeList[3].active = true;
                        cc.game.emit("shieldPressKey",false);
                        cc.Component.EventHandler.emitEvents(this.toolEvent, []);
                    },2)
                },2)
                cc.game.emit("shieldPressKey",false);
                cc.Component.EventHandler.emitEvents(this.toolEvent, []);
            }).start();
        }
    }

    //game30游戏逻辑
    tableMoveUp30(){
        // this.nodeList[1].destroy();
        cc.tween(this.nodeList[0]).by(1,{
            position : cc.v2(0,80)
        }).start();

        cc.tween(this.nodeList[2]).by(1,{
            position : cc.v2(0,80)
        }).call(()=>{
            cc.tween(this.nodeList[2]).by(8,{
                position : cc.v2(0,1100)
            }).call(()=>{
                this.nodeList[5].active = true;
                this.nodeList[7].active = true;
                if(!this.showMaskTable){
                    this.nodeList[3].getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic;
                }else{
                    this.nodeList[2].getComponent(cc.PhysicsBoxCollider).enabled = false;
                }
            }).start();
            cc.tween(cc.Camera.main.node).by(6,{
                position : cc.v2(0,800)
            }).start();
        }).start();
    }

    showMaskTable = false;
    showTableMask(){
        this.showMaskTable = !this.showMaskTable;
        console.log(this.showMaskTable);
        if(this.showMaskTable){
            this.nodeList[4].active = false;
        }else{
            this.nodeList[4].active = true;
        }
    }

    stoneDropFloor(){
        this.nodeList[0].active = false;
        this.nodeList[6].active = true;
    }

    cameraMoveDown30(){
        cc.tween(cc.Camera.main.node).to(0.8,{
            position : cc.v2(0,0)
        }).start();
    }

    openBtnEvent(){
        this.nodeList[2].getComponent(cc.PhysicsBoxCollider).enabled = false;
        cc.tween(this.nodeList[3]).by(0.1,{

        }).call(()=>{
            this.nodeList[3].getComponent(cc.RigidBody).type = cc.RigidBodyType.Dynamic;
        }).start();
    }


    //game31游戏
    showStabGroup31(){
        this.nodeList[0].active = true;
    }

    setCameraPosition31(event){
        if(event[0] == 1){
            cc.Camera.main.node.x += 1250;
        }else if(event[0] == 2){
            cc.Camera.main.node.x -= 1250;
        }
    }

    canUseAction(event){
        let self = event[0];
        let other = event[1];
        if(other.getComponent("roleMediator").curProcessKey == 11){
            event[0].getChildByName("pic").getComponent(cc.Sprite).spriteFrame = this.skinList[0];
            other.getComponent("roleMediator").curProcessKey = null;
            this.nodeList[2].active = true;
            other.getComponent("roleMediator").setRoleProcessKey(null);
            cc.tween(this.nodeList[1]).by(0.3,{
                position : cc.v2(400,0)
            }).start();
        }
    }

    boardMoveUp31(event){
        let self = event[0];
        self .destroy();
        cc.tween(this.nodeList[3]).by(0.3,{
            position : cc.v2(0,280)
        }).start();
        cc.tween(this.nodeList[4]).by(0.3,{
            position : cc.v2(0,280)
        }).call(()=>{
            cc.tween(this.nodeList[3]).by(1,{
                position : cc.v2(0,400)
            }).start();
            cc.tween(this.nodeList[4]).by(1,{
                position : cc.v2(0,400)
            }).start();
            cc.tween(this.nodeList[5]).by(1,{
                position : cc.v2(0,400)
            }).call(()=>{
                cc.Camera.main.node.y += cc.winSize.height;
            }).start();
        }).start();
    }

    hideMask(event){
        event[1].active = false;
        event[0].getChildByName("pic").getComponent(cc.Sprite).spriteFrame = this.skinList[0];
        this.nodeList[6].active = false;
    }

    jerricanEvent(event){
        event[0].active = false;
        event[1].getComponent(cc.MouseJoint).enabled = false;
        event[1].getComponent(cc.PhysicsBoxCollider).senor = true;
        cc.tween(event[1]).to(0.1,{
            position : event[0].position
        }).start();
    }

    //game32
    stabMoveDown32(event){
        event[0].active  = false;
        cc.tween(this.nodeList[0]).by(1.5,{
            position : cc.v2(0,-450)
        }).start();
    }

    stabGroupMoveUp(event){
        event[0].active  = false;
        this.nodeList[0].getComponent(cc.PhysicsBoxCollider).sensor = true;
        this.nodeList[2].active = true;
        cc.tween(this.nodeList[0]).by(3,{
            position : cc.v2(0,cc.winSize.height)
        }).start();
    }

    stabGroupMoveDown(event){
        event[0].active  = false;
        this.nodeList[1].getComponent(cc.PhysicsBoxCollider).sensor = true;
        cc.tween(this.nodeList[1]).by(3,{
            position : cc.v2(0,-cc.winSize.height)
        }).start();
    }

    showAndMoveStab(event){
        event[0].active  = false;
        this.nodeList[2].active = true;
        this.nodeList[3].getComponent(cc.PhysicsBoxCollider).sensor = true;
        cc.tween(this.nodeList[3]).by(3,{
            position : cc.v2(0,-cc.winSize.height)
        }).call(()=>{
            this.nodeList[3].destroy();
        }).start();
    }

    stabMoveLeftRight(event){
        event[0].active  = false;
        cc.tween(this.nodeList[1]).by(0.1,{
            position : cc.v2(cc.winSize.height / 2,0)
        }).start();
        cc.tween(this.nodeList[0]).by(0.1,{
            position : cc.v2(-cc.winSize.height / 2,0)
        }).start();
    }


    //game33
    cameraMoveDown33(){
        if(!this.isMoveDown33){
            cc.Camera.main.node.y -= 500;
            this.isMoveDown33 = true;
        }
    }

    cameraMoveUp33(event){
        if(event[2] == 1){
            if(event[1].y <= event[0].y){
                // cc.Camera.main.node.y += 500;
            }else{
                cc.Camera.main.node.y -= 500;
                this.isMoveDown33 = true;
            }
        }else if(event[2] == 2){
            if(event[1].y <= event[0].y){
                // cc.Camera.main.node.y -= 500;
            }else{
                cc.Camera.main.node.y += 500;
                this.isMoveDown33 = false;
            }
        }
    }

    crashTimes = 0;
    breakDoor33(event){
        if(event[1].getComponent(cc.RigidBody).linearVelocity.y <= -900){
            if(this.crashTimes >= 2){
                this.nodeList[1].active = false;
                this.nodeList[0].active = false;
            }else{
                if(this.crashTimes == 1){
                    this.nodeList[0].getChildByName("pic2").active = false;
                    this.nodeList[0].getChildByName("pic3").active = true;
                }
            }
            this.crashTimes ++;
        }else{
            if(this.crashTimes == 0 && event[1].getComponent(cc.RigidBody).linearVelocity.y <= -100){
                this.nodeList[0].getChildByName("pic1").active = false;
                this.nodeList[0].getChildByName("pic2").active = true;
                cc.tween(this.nodeList[2]).by(0.2,{
                    position : cc.v2(-30,0)
                }).start();
                this.crashTimes ++;
            }
        }
    }

    isMoveDown33 = false;
    openDoorAction33(){
        cc.tween(this.nodeList[4]).by(0.3,{
            position : cc.v2(0,-100)
        }).start();
    }

    hideMaskNode33(){
        this.nodeList[5].active =false;
    }

    //game34
    isMoveCamera = false;
    cameraMoveAction34(event){
        if(event[1].x <= event[0].x && this.isMoveCamera){
            this.isMoveCamera = false;
            cc.Camera.main.node.x += 1400;
        }else if(event[1].x > event[0].x && !this.isMoveCamera){
            this.isMoveCamera = true;
            cc.Camera.main.node.x -= 1400;
        }
    }

    hideMaskNode34(event){
        this.nodeList[0].active = false;
        this.nodeList[1].active = false;
    }

    //game35
    hideMaskNode35(event){
        event[0].active = false;
        this.nodeList[0].active = false;
        this.nodeList[1].getComponent("portalMediator").curAction = actionType.nextLevel;
    }

    hideStone(event){
        event[0].active = false;
        this.nodeList[0].active = false;
    }

    openSwitch35(){
        this.nodeList[1].getComponent("portalMediator").curAction = actionType.pass;
        if(this.nodeList[2].angle == 90){
            this.nodeList[2].angle = -90;
        }else if(this.nodeList[2].angle == -90){
            this.nodeList[2].angle = 90;
        }

    }


    //game37
    isOpened = false;
    openSwitch37(){
        this.isOpened = !this.isOpened;
        if(this.isOpened){
            for(let i in this.nodeList[0].children){
                this.nodeList[0].children[i].getComponent(cc.Sprite).spriteFrame = this.skinList[i];
            }
        }else{
            for(let i in this.nodeList[0].children){
                this.nodeList[0].children[i].getComponent(cc.Sprite).spriteFrame = this.skinList[6];
            }
        }
    }

    cameraMoveAction37(event,data){
        if(parseInt(data) == 1){
            cc.Camera.main.node.x += 1500;
        }else if(parseInt(data) == 2){
            cc.Camera.main.node.x -= 1500;
        }
    }

    passIndex = "";
    isCheckOver = false;
    roleChangePosition(event,data){
        let pos = null;
        let pos2 = null;
        this.passIndex  =  this.passIndex + data;
        switch (parseInt(data)) {
            case 1 :
                pos = this.nodeList[5].convertToWorldSpaceAR(cc.v2(0,0));
                pos2 = cc.find("Canvas").convertToNodeSpaceAR(pos);
                cc.tween(this.nodeList[7]).to(0.01,{
                    position : cc.v2(pos2.x,pos2.y)
                }).start();
                break;
            case 2 :
                pos = this.nodeList[6].convertToWorldSpaceAR(cc.v2(0,0));
                pos2 = cc.find("Canvas").convertToNodeSpaceAR(pos);
                cc.tween(this.nodeList[7]).to(0.01,{
                    position : cc.v2(pos2.x,pos2.y)
                }).start();
                break;
            case 3 :
                pos = this.nodeList[2].convertToWorldSpaceAR(cc.v2(0,0));
                pos2 = cc.find("Canvas").convertToNodeSpaceAR(pos);
                cc.tween(this.nodeList[7]).to(0.01,{
                    position : cc.v2(pos2.x,pos2.y)
                }).start();
                break;
            case 4 :
                pos = this.nodeList[1].convertToWorldSpaceAR(cc.v2(0,0));
                pos2 = cc.find("Canvas").convertToNodeSpaceAR(pos);
                cc.tween(this.nodeList[7]).to(0.01,{
                    position : cc.v2(pos2.x,pos2.y)
                }).start();
                break;
            case 5 :
                pos = this.nodeList[4].convertToWorldSpaceAR(cc.v2(0,0));
                pos2 = cc.find("Canvas").convertToNodeSpaceAR(pos);
                cc.tween(this.nodeList[7]).to(0.01,{
                    position : cc.v2(pos2.x,pos2.y)
                }).start();
                break;
            case 6 :
                pos = this.nodeList[2].convertToWorldSpaceAR(cc.v2(0,0));
                pos2 = cc.find("Canvas").convertToNodeSpaceAR(pos);
                cc.tween(this.nodeList[7]).to(0.01,{
                    position : cc.v2(pos2.x,pos2.y)
                }).start();
                if(this.passIndex.indexOf("123456") > -1 && !this.isCheckOver){
                    this.isCheckOver = true;
                    cc.tween(this.nodeList[8]).by(0.5,{
                        angle : 180
                    }).start();
                    this.nodeList[10].y -= 100;
                    this.nodeList[11].y -= 150;
                    cc.tween(this.nodeList[9]).by(0.1,{
                        angle : 180
                    }).call(()=>{
                        cc.tween(this.nodeList[9]).by(0.1,{
                            position : cc.v2(0,-150)
                        }).start();
                    }).start();
                }
                break;
        }
    }

    //game38
    isDoOver1 = false;
    isDoOver2 = false;
    isDoOver3 = false;
    isDoOver4 = false;
    triggerList = [];
    tableClose(event,data){
        if(this.triggerList.indexOf(event[0]) < -1){
            this.triggerList.push(event[0]);
        }
        switch (parseInt(data)) {
            case 1 :
                if(this.isDoOver1) return;
                this.isDoOver1 = true;
                cc.tween(this.nodeList[0])
                    .by(1.8,{position : cc.v2(0,140)})
                    .delay(1)
                    .by(1.8,{position : cc.v2(0,-140)})
                    .start();
                cc.tween(this.nodeList[1])
                    .by(1.8,{position : cc.v2(0,-140)})
                    .delay(1)
                    .by(1.8,{position : cc.v2(0,140)})
                    .call(()=>{
                        this.isDoOver1 = false;
                    })
                    .start();
                    break;
            case 2 :
                if(this.isDoOver2) return;
                this.isDoOver2 = true;
                cc.tween(this.nodeList[2])
                    .by(1.3,{position : cc.v2(0,140)})
                    .delay(1)
                    .by(2,{position : cc.v2(0,-140)})
                    .start();
                cc.tween(this.nodeList[3])
                    .by(1.3,{position : cc.v2(0,-140)})
                    .delay(1)
                    .by(2,{position : cc.v2(0,140)})
                    .call(()=>{
                        this.isDoOver2 = false;
                    })
                    .start();
                    break;
            case 3 :
                if(this.isDoOver3) return;
                this.isDoOver3 = true;
                cc.tween(this.nodeList[4])
                    .by(1,{position : cc.v2(0,140)})
                    .delay(1)
                    .by(1,{position : cc.v2(0,-140)})
                    .start();
                cc.tween(this.nodeList[5])
                    .by(1,{position : cc.v2(0,-140)})
                    .delay(1)
                    .by(1,{position : cc.v2(0,140)})
                    .call(()=>{
                        this.isDoOver3 = false;
                    })
                    .start();
                    break;
            case 4 :
                if(this.isDoOver4) return;
                this.isDoOver4 = true;
                cc.tween(this.nodeList[8])
                    .to(0.8,{y : -135})
                    .delay(1)
                    .to(0.8,{y : -245})
                    .start();
                cc.tween(this.nodeList[9])
                    .to(1,{y: 101})
                    .delay(1)
                    .to(1,{y : 201})
                    .call(()=>{
                        this.isDoOver4 = false;
                    })
                    .start();
                break;
        }
    }

    hideEyes(){
        this.nodeList[6].getComponent(cc.Sprite).spriteFrame = this.skinList[0];
        this.nodeList[7].y = -1000;
    }

    showEyes(){
        this.nodeList[6].getComponent(cc.Sprite).spriteFrame = this.skinList[1];
        this.nodeList[7].y = 0;
    }

    //game43
    openTimes = 0;
    openDoor43(event,data){
        if(this.openTimes >= 4){
            cc.Component.EventHandler.emitEvents(this.toolEvent, []);
        }
        if(this.openTimes + 1 == parseInt(data)){
            event[0].children[0].active = true;
            event[0].off("touchstart",event[1].TouchStart,event[1]);
            this.openTimes++;
        }
    }

    //game44
    showMask44 = true;
    showTableMask44(){
        this.showMask44 = !this.showMask44;
        this.nodeList[0].active = this.showMask44;
    }

    tableMoveUp44(){
        cc.tween(this.nodeList[1]).by(0.5,{
            position : cc.v2(0,200)
        }).start();
        this.nodeList[0].getComponent(cc.PhysicsBoxCollider).enabled = false;
    }

    isMoving44 = false;
    cameraChangePosition44(){
        console.log(this.isMoving44);
        if(!this.isMoving44){
            cc.Camera.main.node.x -= 1625;
        }else{
            cc.Camera.main.node.x += 1625;
        }
        this.isMoving44 = !this.isMoving44;
    }

    showKey44(){
        this.nodeList[2].active = true;
        this.nodeList[3].active = true;
    }

    //game45
    roleDie(){
        cc.director.getPhysicsManager().enabled = false;
        cc.game.emit("shieldPressKey",true);
        cc.game.emit("GameOver");
        settingMediator.doVibration(2);
        let spk = cc.find("Canvas/role").getChildByName("spine").getComponent(sp.Skeleton);
        spk.setAnimation(0,"die",false);
        cc.game.emit("petDie");
        this.scheduleOnce(()=>{
            cc.game.emit("gameLose",1);
        },2);
    }

    dropKey(){
        this.nodeList[0].getChildByName("light").active = false;
        this.nodeList[0].getChildByName("pic").active = false;
        this.nodeList[0].getComponent(cc.RigidBody).gravityScale = 10;
        this.nodeList[0].getComponent(cc.RigidBody).linearVelocity = cc.v2(0,-50);
        this.nodeList[0].removeComponent(cc.MouseJoint);
        this.nodeList[1].active = false;
    }

    //game46
    hideMask46(){
        this.nodeList[0].active = false;
    }


    //game48
    openGameDoor(event,data){
        this.nodeList[1].group = "default";
        cc.tween(this.nodeList[1]).to(0.01,{
            position : cc.v2(this.nodeList[2].x,this.nodeList[2].y)
        }).call(()=>{
            this.nodeList[1].group = "role";
            // this.scheduleOnce(()=>{
            //     cc.Component.EventHandler.emitEvents(this.toolEvent, []);
            // },2)
        }).start();
        // this.nodeList[1].position = this.nodeList[2].position;
        // this.scheduleOnce(()=>{
        //     cc.Component.EventHandler.emitEvents(this.toolEvent, []);
        // },2)
    }

    //game49
    moveMaskNode(){
        cc.tween(this.nodeList[0]).by(1,{
            position : cc.v2(-200,0)
        }).start();
    }

    //game50 相机移动
    cameraMoveAction49(){
        cc.Camera.main.node.y -= 750;
    }

    cameraPositionLeft = false;
    cameraMoveAction491(event){
        if(!this.cameraPositionLeft && event[1].x >= -cc.view.getVisibleSize().width / 2 - 50){
            // cc.tween(event[1]).by(0.01,{
            //     position : cc.v2(this.nodeList[3].x,this.nodeList[3].y)
            // }).start();
            cc.Camera.main.node.x = -cc.view.getVisibleSize().width;
            this.cameraPositionLeft = true;
        }else if(this.cameraPositionLeft && event[1].x <= -cc.view.getVisibleSize().width / 2 - 50){
            cc.Camera.main.node.x = 0;
            this.cameraPositionLeft = false;
        }
    }

    //game50
    stabMoveAction50(){
        let action1 = ()=>{
            cc.tween(this.nodeList[0]).to(3.2,{
                y : -105
            }).call(()=>{
                cc.tween(this.nodeList[0]).to(3.2,{
                    y : 0
                }).call(()=>{
                    action1()
                }).start();
            }).start();
            cc.tween(this.nodeList[4]).to(3.2,{
                y : -105
            }).call(()=>{
                cc.tween(this.nodeList[4]).to(3.2,{
                    y : 0
                }).start();
            }).start();
        };

        let action2 = ()=>{
            cc.tween(this.nodeList[1]).to(2.5,{
                y : -105
            }).call(()=>{
                cc.tween(this.nodeList[1]).to(2.5,{
                    y : 0
                }).call(()=>{
                    action2()
                }).start();
            }).start();
            cc.tween(this.nodeList[3]).to(2.5,{
                y : -105
            }).call(()=>{
                cc.tween(this.nodeList[3]).to(2.5,{
                    y : 0
                }).start();
            }).start();
        };

        let action3 = ()=>{
            cc.tween(this.nodeList[2]).to(3.5,{
                y : -105
            }).call(()=>{
                cc.tween(this.nodeList[2]).to(3.5,{
                    y : 0
                }).call(()=>{
                    action3()
                }).start();
            }).start();
        };

        action1();
        action2();
        action3();

    }


    //特殊关卡
    isCreateView = false;
    specialLevel(event,data){
        if(this.isCreateView) return;
        this.isCreateView = true;

        Tool.loadPrefab("prefabs/callDragon",(res)=>{
            let view = cc.instantiate(res);
            view.getComponent("callDragonMediator").setCallBack(true,()=>{
                event[0].active = false;
                mainManage.createToast("Selamat! Anda telah mendapatkan seekor hewan peliharaan");
                let arr = gameData.getPetCurSkin();
                if(arr.length >= gameData.judgeWearPetNumber(gameData.curRankTitle)){
                // if(arr.length >= 2){
                    cc.game.emit("showMorePet",15);
                }else{
                    arr.push(15);
                    gameData.setPetCurSkin(arr);
                    gameData.saveLastPetSkin();
                    cc.game.emit("resetPet");
                }
            },()=>{
                this.isCreateView = false;
            });
            view.parent = cc.find("Canvas");
        })
    }


    //特殊关卡过关
    specialPassLevel(event){
        cc.director.loadScene("main",()=>{
            Tool.loadPrefab("mainPrefab/levelView",(res)=>{
                let view = cc.instantiate(res);
                view.parent = cc.find("Canvas");
            });
        })
    }

    //特殊关卡
    roleMovePosition = null;
    showSpecialBtn(event,data){
        if(parseInt(data) == 1){

            AudioManage.playSFX(soundList.fireBurn1,true,true,1);
            AudioManage.playSFX(soundList.fireDie);
            let spk = this.nodeList[4].getComponent(sp.Skeleton);
            spk.setAnimation(0,"disappear",false);
            spk.setCompleteListener(()=>{
                this.nodeList[4].active = false;
            });
            this.nodeList[2].active = false;
            this.nodeList[0].getComponent("conversationWindow").setCallBack(2,()=>{
                this.nodeList[3].active = true;
            });
            this.nodeList[0].active = true;

        }

        if(parseInt(data) == 2){
            AudioManage.playSFX(soundList.openlock);
            this.nodeList[5].active = false;
            this.nodeList[3].active = false;
            this.scheduleOnce(()=>{
                let children = this.nodeList[5].parent.children;
                for(let i in children){
                    cc.tween(children[i]).by(3,{
                        x : -350
                    }).start();
                }
                cc.tween(this.nodeList[6]).by(3,{
                    x : -350
                }).call(()=>{
                    this.nodeList[13].active = true;
                    this.nodeList[14].active = true;
                    this.roleMovePosition = cc.v2(this.nodeList[6].x,this.nodeList[6].y);
                }).start();
            },1)
        }
    }

    getBugSkin(event){
        event[0].active = false;
        this.nodeList[7].active = true;
        this.nodeList[8].active = false;
        this.nodeList[9].active = true;
        this.nodeList[12].active = true;
        let spk = this.nodeList[12].getComponent(sp.Skeleton);
        spk.setCompleteListener(()=>{
            this.nodeList[12].active = false;
        });
        cc.tween(this.nodeList[11])
            .to(0.2,{scale : 1})
            .delay(2)
            .call(()=>{
                this.nodeList[11].active = false;
            })
            .start();
        AudioManage.playSFX(soundList.colour);
        gameData.saveRoleSkin(14);
        gameData.setCurUseRoleSkin(14);
        gameData.saveLastRoleSkin();
        cc.game.emit("setGameRoleSkin",15);
        cc.tween(event[1]).to(0.01,{
            position : this.roleMovePosition
        }).start();
    }

    @property()
    otherScene = false;

    roleRelivePosition(){
        if(!this.otherScene){
            this.nodeList[6].active = false;
            cc.game.emit("shieldPressKey", true);
            cc.tween(this.nodeList[6]).to(0.01,{
                position : cc.v2(this.nodeList[10].x,this.nodeList[10].y + 100)
            }).call(()=>{
                this.nodeList[6].active = true;
                cc.game.emit("shieldPressKey", false);
                let spk = this.nodeList[6].getChildByName("spine").getComponent(sp.Skeleton);
                spk.setAnimation(0,"animation",true);
            }).start();
        }else{
            this.nodeList[0].active = false;
            cc.game.emit("shieldPressKey", true);
            cc.tween(this.nodeList[0]).to(0.01,{
                position : cc.v2(this.nodeList[1].x,this.nodeList[1].y + 100)
            }).call(()=>{
                this.nodeList[0].active = true;
                cc.game.emit("shieldPressKey", false);
                let spk = this.nodeList[0].getChildByName("spine").getComponent(sp.Skeleton);
                spk.setAnimation(0,"animation",true);
            }).start();
        }
    }

    //魔王关卡 51

    MaraLevel11(){
        cc.game.emit("shieldPressKey", true);
        this.scheduleOnce(()=>{
            this.nodeList[1].active = true;
            this.scheduleOnce(()=>{
                this.nodeList[1].active = false;
                this.nodeList[2].active = true;
                this.scheduleOnce(()=>{
                    this.nodeList[2].active = false;
                    this.nodeList[3].active = true;
                    this.scheduleOnce(()=>{
                        this.nodeList[3].active = false;
                        this.nodeList[8].active = true;
                        let spk = this.nodeList[8].getComponent(sp.Skeleton);
                        spk.setAnimation(0,"animation",false);
                        this.scheduleOnce(()=>{
                            this.nodeList[6].active = false;
                        },0.8);
                        this.nodeList[7].getChildByName("effect").active = true;
                        let spk2 = this.nodeList[7].getChildByName("effect").getComponent(sp.Skeleton);
                        spk2.setAnimation(0,"animation",false);
                        cc.game.emit("setGameRoleSkin",16);
                        this.nodeList[0].active = true;
                        cc.game.emit("shieldPressKey", false);
                    },2);
                },2)
            },2)
        },2)

    }

    MaraLevel12(event){
        event[0].active = false;
        cc.tween(cc.Camera.main.node).by(0.8,{
            position : cc.v2(900,0)
        }).start();
        this.scheduleOnce(()=>{
            cc.tween(this.node)
                .call(()=>{
                    cc.tween(this.nodeList[4]).by(0.5,{
                        position : cc.v2(0,-cc.winSize.height - 500)
                    }).start();
                    cc.tween(this.nodeList[5]).by(0.5,{
                        position : cc.v2(0,cc.winSize.height + 500)
                    }).start();
                    cc.tween(this.nodeList[9]).by(0.3,{
                        position : cc.v2(-20,0)
                    }).start();
                }).start();
        },5)
    }

    // MaraLevel13(event){
    //     event[0].active = false;
    // }

    showTable21 = false;
    MaraLevel21(){
        if(this.showTable21){
            this.showTable21 = false;
            this.nodeList[0].active = false;
        }else{
            this.showTable21 = true;
            this.nodeList[0].active = true;
        }
    }

    MaraLevel31(){
        cc.tween(this.nodeList[0]).by(0.2,{position : cc.v2(-150,0)})
            .start();
        cc.tween(this.nodeList[1]).by(0.5,{
            position : cc.v2(0,-cc.winSize.height - 500)
        }).start();
        cc.tween(this.nodeList[2]).by(0.5,{
            position : cc.v2(0,cc.winSize.height + 500)
        }).start();
        cc.tween(this.nodeList[3]).by(0.2,{
            position : cc.v2(0,300)
        }).start();
    }

    showMask41 = false;
    MaraLevel41(){
        if(this.showMask41){
            this.nodeList[0].active = true;
            this.showMask41 = false;
        }else{
            this.nodeList[0].active = false;
            this.showMask41 = true;
        }
    }

    MaraLevel51(){
        this.nodeList[0].getComponent(cc.Label).string = "我只能帮你到这里了";
        this.scheduleOnce(()=>{
            this.nodeList[0].getComponent(cc.Label).string = "除非你愿意带我离开";
            this.scheduleOnce(()=>{
                this.nodeList[0].getComponent(cc.Label).string = "";
            },1);
            cc.game.emit("shieldPressKey", false);
        },3)
    }

    MaraLevel52(){
        Tool.loadPrefab("prefabs/callChicken",(res)=>{
            let view = cc.instantiate(res);
            view.getComponent("callChickenMediator").setCallBack(()=>{
                this.nodeList[1].active = false;
            });
            view.parent = cc.find("Canvas");
        });
    }

    MaraLevel56(){
        Tool.loadPrefab("prefabs/showLockStone",(res)=>{
            let view = cc.instantiate(res);
            view.getComponent("showLockStone").setCallBack(()=>{
                for(let i in this.nodeList[5].children){
                    this.nodeList[5].children[i].active = false;
                }
                this.nodeList[5].getComponent(cc.RigidBody).enabledContactListener = true;
                this.nodeList[5].active = false;
                this.nodeList[5].active = true;
                // cc.tween(this.nodeList[5]).by(0.2,{
                //     position : cc.v2(0,100)
                // }).start();
                gameData.unlockPrinceStone5 = true;
                gameData.savePrinceLevelLocalPart1();
            });
            view.parent = cc.find("Canvas");
        });
    }

    MaraLevel57(){
        Tool.loadPrefab("prefabs/callEgg",(res)=>{
            let view = cc.instantiate(res);
            view.getComponent("callEggMediator").setCallBack(()=>{
                this.nodeList[6].active = false;
                let arr = gameData.getPetCurSkin();
                if(arr.length >= gameData.judgeWearPetNumber(gameData.curRankTitle)){
                // if(arr.length >= 2){
                    cc.game.emit("showMorePet",16);
                }else{
                    arr.push(16);
                    gameData.setPetCurSkin(arr);
                    gameData.saveLastPetSkin();
                    cc.game.emit("resetPet");
                }
            });
            view.parent = cc.find("Canvas");
        });
    }

    MaraLevel53(){
        this.nodeList[2].active = false;
    }

    MaraLevel54(){
        this.nodeList[3].active = false;
    }

    curSceneIndex = 0;
    MaraLevel55(event){
       if(event[1].x > event[0].x && this.curSceneIndex == 0){
           cc.tween(cc.Camera.main.node).to(1,{
               position : cc.v2(-1480,0)
           }).call(()=>{
               this.curSceneIndex = 1;
           }).start();
       }else if(event[1].x <= event[0].x && this.curSceneIndex == 1){
           cc.tween(cc.Camera.main.node).to(1,{
               position : cc.v2(0,0)
           }).call(()=>{
               this.curSceneIndex = 0;
           }).start();
       }
    }

    MaraLevel58(){
        cc.game.emit("shieldPressKey", true);
        this.nodeList[8].getComponent(cc.Label).string = "做成卤蛋还是荷包蛋呢…";
        this.scheduleOnce(()=>{
            this.nodeList[8].getComponent(cc.Label).string = "";
            this.nodeList[7].getComponent(cc.Label).string = "大魔王，你居然藏在这里！";
            this.scheduleOnce(()=>{
                this.nodeList[7].getComponent(cc.Label).string = "放开那个金蛋！";
                this.scheduleOnce(()=>{
                    this.nodeList[9].scaleX *= -1;
                    this.nodeList[7].getComponent(cc.Label).string = "";
                    this.scheduleOnce(()=>{
                        this.nodeList[8].getComponent(cc.Label).string = "…你为什么总要打扰本大王吃饭？";
                        this.scheduleOnce(()=>{
                            this.nodeList[8].getComponent(cc.Label).string = "哼，区区卤蛋，不要也罢";
                            this.scheduleOnce(()=>{
                                this.nodeList[8].getComponent(cc.Label).string = "可是不激活石阶，你也拿不到它！";
                                this.scheduleOnce(()=>{
                                    this.nodeList[8].getComponent(cc.Label).string = "";
                                    cc.tween(this.nodeList[9]).by(1,{
                                        position : cc.v2(0,400)
                                    }).start();
                                    cc.game.emit("shieldPressKey", false);
                                },3)
                            },3)
                        },3)
                    },1)
                },1)
            },3)
        },3);
    }


    clickTimes59 = 11;
    MaraLevel61(event,data){
        if(parseInt(data) == 1){
            event[0].parent.getComponent(cc.Sprite).spriteFrame = this.skinList[1];
        }else if(parseInt(data) == 2){
            event[0].parent.getComponent(cc.Sprite).spriteFrame = this.skinList[0];
        }else if(parseInt(data) == 3){
            event[0].getComponent(cc.Sprite).spriteFrame = this.skinList[1];
            this.nodeList[0].getComponent(cc.PhysicsBoxCollider).enabled = false;
        }
        this.clickTimes59--;
        if(this.clickTimes59 == 0){
            cc.tween(this.nodeList[1]).by(0.2,{
                position : cc.v2(0,200)
            }).start();
        }
        console.log(this.clickTimes59);
    }

    MaraLevel62(){
        this.nodeList[0].off("touchend",this.MaraLevel62,this);
        // this.nodeList[0].group = "trigger";
        cc.tween(this.nodeList[0]).by(0.2,{
            position : cc.v2(0,-100)
        }).call(()=>{
            this.nodeList[0].getComponent(cc.PhysicsBoxCollider).enabled = true;
        }).start();
    }


    MaraLevel71(event,data){
        cc.Component.EventHandler.emitEvents(this.toolEvent, event);
    }

    MaraLevel72(event,data) {
        cc.game.emit("shieldPressKey", true);
        if (parseInt(data) == 1) {
            cc.tween(this.nodeList[2]).to(0.01, {
                position: cc.v2(this.nodeList[0].x, this.nodeList[0].y)
            }).call(() => {
                cc.game.emit("shieldPressKey", false);
            }).start();
            cc.Camera.main.node.x = 1625;
        } else if (parseInt(data) == 2) {
            cc.tween(this.nodeList[2]).to(0.01, {
                position: cc.v2(this.nodeList[1].x, this.nodeList[1].y)
            }).call(() => {
                cc.game.emit("shieldPressKey", false);
            }).start();
            cc.Camera.main.node.x = 0;
        }
    }

    MaraLevel73(){
        YchlStatistic.ADSwitchState((res)=>{
            if(res){
                cc.game.emit("shieldPressKey", true);
                if(!gameData.showConversation8){
                    this.nodeList[5].getChildByName("effect").active = true;
                    let spk = this.nodeList[5].getChildByName("effect").getComponent(sp.Skeleton);
                    spk.setCompleteListener(()=>{
                        this.nodeList[5].getChildByName("spine").active = true;
                        this.nodeList[6].getComponent("conversationWindow").setCallBack(4,()=>{
                            cc.tween(this.nodeList[5]).by(0.2,{
                                position : cc.v2(0,600)
                            }).call(()=>{
                                this.nodeList[5].active = false;
                                this.nodeList[4].active = true;
                                cc.game.emit("shieldPressKey", false);
                            }).start();
                        });
                        this.nodeList[6].active = true;
                    });
                    gameData.showConversation8 = true;
                    gameData.savePrinceLevelLocalPart1();
                }else{
                    this.nodeList[17].active = true;
                    cc.game.emit("shieldPressKey", false);
                }
            }
        })
    }

    MaraLevel74(event,data){
        if(this.nodeList[7].x < 0){
            cc.Camera.main.node.x = -1625;
        }else{
            cc.Camera.main.node.x = 750;
        }
    }

    MaraLevel81(){
        if(cc.Camera.main.node.x >= 0){
            cc.Camera.main.node.x = -1625;
            cc.Camera.main.node.y = 0;
        }else{
            cc.Camera.main.node.x = 1625 * 2;
            cc.Camera.main.node.y = 750;
        }
    }

    MaraLevel82(){
        cc.tween(this.nodeList[0]).by(3,{
            position : cc.v2(-1370,0)
        }).start();
    }



    MaraLevel84(){
        this.nodeList[4].active = false;
    }

    MaraLevel85(){
        // cc.game.emit("shieldPressKey", true);
        // gameData.showConversation81 = true;
        // gameData.savePrinceLevelLocalPart1();
        // cc.tween(this.nodeList[6]).by(0.2,{
        //     position : cc.v2(0,300)
        // }).call(()=>{
        //     this.nodeList[14].active = false;
        //     this.nodeList[7].active = true;
        //     cc.game.emit("shieldPressKey", false);
        // }).start();
    }

    MaraLevel86(){
        cc.game.emit("shieldPressKey", true);
        Tool.loadPrefab("prefabs/ChristmasDay",(res)=>{
            let view = cc.instantiate(res);
            view.getComponent("ChristmasMediator").setCallBack(5,()=>{
                //解密游戏完成
                // if(gameData.showConversation82){
                //     cc.game.emit("shieldPressKey", false);
                // }else{
                    // gameData.showConversation82 = true;
                    // gameData.savePrinceLevelLocalPart1();
                    this.nodeList[7].active = false;
                    //大魔王飞回来
                    cc.tween(this.nodeList[6]).by(0.2,{
                        position : cc.v2(0,300)
                    }).call(()=>{
                        //飞回来对话
                        cc.tween(this.nodeList[8])
                            .by(3,{position : cc.v2(-600,0)})
                            .start();
                        this.scheduleOnce(()=>{
                            cc.tween(this.nodeList[9]).by(2,{
                                position : cc.v2(-450,0)
                            }).start()
                        },0.8);
                        cc.game.emit("shieldPressKey", false);
                    }).start();
                // }

            });
            view.zIndex = 500;
            view.parent = cc.find("Canvas");
        })
    }

    showMask87 = false;
    MaraLevel87(){
        if(this.showMask87){
            this.nodeList[10].active = true;
            this.showMask87 = false;
        }else{
            this.nodeList[10].active = false;
            this.showMask87 = true;
        }
    }

    MaraLevel88(){
        this.nodeList[11].active = true;
    }

    MaraLevel89(){
        Tool.loadPrefab("prefabs/ChristmasDay",(res)=>{
            let view = cc.instantiate(res);
            view.getComponent("ChristmasMediator").setCallBack(3,()=>{
                this.nodeList[13].active = false;
            });
            view.zIndex = 500;
            view.parent = cc.find("Canvas");
        })
    }

    MaraLevel810(){
        Tool.loadPrefab("prefabs/ChristmasDay",(res)=>{
            let view = cc.instantiate(res);
            view.getComponent("ChristmasMediator").setCallBack(4,()=>{
                this.nodeList[15].active = false;
            });
            view.zIndex = 500;
            view.parent = cc.find("Canvas");
        })
    }

    isCreateViewThread = false;
    MaraLevel811(){
        if(this.isCreateViewThread) return;
        this.isCreateViewThread = true;
        Tool.loadPrefab("prefabs/ChristmasDay",(res)=>{
            let view = cc.instantiate(res);
            view.getComponent("ChristmasMediator").setCallBack(1,()=>{
                this.isCreateViewThread = false;
            },()=>{
                this.isCreateViewThread = false;
            });
            view.zIndex = 500;
            view.parent = cc.find("Canvas");
        })
    }

    touchTimes91 = 0;
    MaraLevel91(event,data){
        console.log("1111");
        this.touchTimes91 ++;
        this.nodeList[parseInt(data) - 1].getComponent(cc.Sprite).spriteFrame = this.skinList[0];
        if(this.touchTimes91 == 3){
            this.nodeList[3].active = true;
        }
    }

    MaraLevel92(){
        if(cc.Camera.main.node.x >= 0){
            cc.Camera.main.node.x = -1625;
            cc.Camera.main.node.y = 0;
        }else{
            cc.Camera.main.node.x = 0;
            cc.Camera.main.node.y = 0;
        }
    }

    MaraLevel101(){
        cc.tween(this.nodeList[0]).by(0.2,{
            position : cc.v2(0,-170)
        }).start();

        cc.tween(this.nodeList[1]).by(0.2,{
            position : cc.v2(0,-170)
        }).start();
    }
}
